--
-- Author:      feilong
-- DateTime:    2019-12-16 17:19:33
-- Description: 服务管理


require "skynet.manager"
local skynet = require "skynet"
local NodeMessage = import("NodeMessage")
local MessageDispatch = import("MessageDispatch")
local MessageHandler = import("manager.MessageHandler")
local ClusterManager = import("ClusterManager")
local ServerInfo = import("ServerInfo")

-- global = {} --服务只有一个全局变量，已在class.lua里声明

local function init()

	local node_message = NodeMessage.new()
	local message_dispatch = MessageDispatch.new()	
	local message_handler = MessageHandler.new(message_dispatch, node_message)
	local cluster_manager = ClusterManager.new(message_dispatch)
	local server_info = ServerInfo.new() --节点相关信息

	global.node_message = node_message
	global.message_dispatch = message_dispatch
	global.message_handler = message_handler
	global.cluster_manager = cluster_manager
	global.server_info = server_info	
	
	skynet.dispatch("lua", message_dispatch:dispatch())		

	--开启集群节点
	global.cluster_manager:open(server_info)
end
---------------------------------------------------------
-- skynet
---------------------------------------------------------

skynet.start(function()

	skynet.register('.manager') --注册服务名字
	init()	
end)